﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using CartoLab.GeometryLib.Geometries;
using System.Drawing;
using CartoLab.GeometryLib.AlgorithmExtent;

namespace CartoLab.ShortestPath
{
    public class Node:ICloneable
    {
        private string _id;
        private List<Edge> edgeList = new List<Edge>();//Edge的集合－－出边表

        public Node(string id, Coordinate position)
        {
            this._id = id;
            this.postition = position;
        }

        public string ID
        {
            get
            {
                return this._id;
            }
        }

        public Edge[] Edges
        {
            get
            {
                return this.edgeList.ToArray();
            }
        }

        public void AddEdge(Edge edge)
        {
            this.edgeList.Add(edge);
        }

        private Coordinate postition = null;

        public Coordinate Postition
        {
            get { return postition; }
            set { postition = value; }
        }

        public void AddEdge(Edge[] edges)
        {
            this.edgeList.AddRange(edges);
        }

        Brush brush = new SolidBrush(Color.LimeGreen);
        internal void Render(Graphics g)
        {
            g.FillEllipse(brush,
                          (float)this.Postition.X - 3,
                          (float)this.Postition.Y - 3,
                          6,
                          6);

            System.Drawing.Drawing2D.Matrix matrixOld = g.Transform;
            PointF pf = new PointF((float)this.Postition.X,
                                           (float)this.Postition.Y);
            g.TranslateTransform(pf.X, pf.Y);
            g.ScaleTransform(1, -1);

            g.DrawString(this.ID.Replace("Node_", ""),
                         new Font("微软雅黑", 8),
                         new SolidBrush(Color.Blue),
                         new PointF());

            g.Transform = matrixOld;
        }

        private double minDistanceToFixedDoor = 0;
        /// <summary>
        /// The min distance to fixed doors.
        /// </summary>
        public double MinDistanceToFixedDoor
        {
            get 
            {
                return minDistanceToFixedDoor;
            }
            set
            {
                minDistanceToFixedDoor = value;
            }
        }

        internal bool RemoveEdge(Edge edge)
        {
            if (this.edgeList.Contains(edge))
            {
                this.edgeList.Remove(edge);
                return true;
            }
            return false;
            
        }

        public object Clone()
        {
            Node nodeClone = new Node(this.ID, this.Postition);
            nodeClone.AddEdge(this.Edges);
            return nodeClone;
        }
    }
}
